package com.iris.live.services.common.reconsitution;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class CollectionUtils {

	private static final char SPLIT_STR=',';
	public static final String SPLIT_STR_STRING=",";

	public static boolean isEmpty(Collection coll){
		return coll == null || coll.isEmpty();
	}

	public static boolean isNotEmpty(Collection coll){
		return ! isEmpty(coll);
	}


	/**
	 * 集合转string CollectionUtils.java
	 *
	 * @param collection
	 * @param split
	 * @return String
	 */
		public static String CollectionToString(Collection<String> collection,
		char split) {
			StringBuffer sBuilder = new StringBuffer();
			if (collection instanceof java.util.Set) {
				Iterator<String> iterator = collection.iterator();
				while (iterator.hasNext()) {
					String string = iterator.next();
					sBuilder.append(string).append(split);
				}

			} else if (collection instanceof List) {
				for (String string : collection) {
					sBuilder.append(string).append(split);
				}
			}
			if (sBuilder.length()>0) {
				sBuilder.deleteCharAt(sBuilder.length()-1);
			}
			return sBuilder.toString();
	}


	/**
	 * 数组转List
	 * @param ids
	 * @return
	 */
	public static List<String> ArrToCollection(String[] ids) {
		List<String> list =  new ArrayList<String>();
		for (String id :ids ) {
			list.add(id);
		}
		return list;
	}

	
	/**
	 * 字符串转list
	 *CollectionUtils.java 
	 *@return
	 *List<String>
	 */
	public static List<String> dealStringWithComma(String target,String split){
		List<String> strings = new ArrayList<>();
		for (String temp : target.split(split)) {
			strings.add(temp);
		}
		return strings;
	}

	/**
	 * 集合转换为sql in查询字符串
	 * @param values
	 * @return
	 */
	public static String getStr4SQLINParam(List<String> values){
		String str = "";
		for (int i = 0; i < values.size(); i++) {
			str += "" + values.get(i) + ", ";
		}
		return str.substring(0, str.length() - 2);
	}


	public  static void main(String [] args){
		String id ="1";
		String[] ids = id.split(CollectionUtils.SPLIT_STR_STRING);
		System.out.println(ArrToCollection(ids));
	}
	
	

}
